package com.heima.wemedia.config;
import com.heima.common.constants.message.PublishArticleConstants;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 * 声明定时发布文章
 * 所需的 所有交换机  队列 及 绑定关系
 **/
@Configuration
public class DeclarePubArticleRabbitConfig {

    @Bean
    Queue publishArticleQueue(){
        return QueueBuilder.durable(PublishArticleConstants.PUBLISH_ARTICLE_QUEUE).build();
    }

    @Bean
    DirectExchange delayExchange(){
        DirectExchange directExchange = new DirectExchange(PublishArticleConstants.DELAY_DIRECT_EXCHANGE);
        directExchange.setDelayed(true);//使用延时交换机
        return directExchange;
    }

    @Bean
    Binding binding(){
        return BindingBuilder.bind(publishArticleQueue()).to(delayExchange()).with(
                PublishArticleConstants.PUBLISH_ARTICLE_ROUTE_KEY
        );
    }
}